package queries;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import entitys.Customer;

public class GetCustomerListQuery {
/**
 * Execute query from internal customers table
 * @param conn
 * @return
 */
	public static ArrayList<Customer> exe(Connection conn) {
		ArrayList<Customer> arr = new ArrayList<Customer>();
		ResultSet res = null; 
		Statement stmt;
			try {
				stmt = conn.createStatement();
				res = stmt.executeQuery("SELECT * from ccrm.customer; ");
				while(res.next())
				{
					arr.add(new Customer(res.getString(2), res.getString(3), res.getString(6), res.getString(4), res.getString(5), res.getString(1), res.getInt(7)==1,res.getString(8)));
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		
		return arr;
		
	}
/**
 * Execute query from external customer table
 * @param conn
 * @return
 */
	public static ArrayList<Customer> exeExternal(Connection conn) {
		ArrayList<Customer> arr = new ArrayList<Customer>();
		ResultSet res = null; 
		Statement stmt;
			try {
				stmt = conn.createStatement();
				res = stmt.executeQuery("SELECT * from ccrm.externalcustomer; ");
				while(res.next())
				{
					arr.add(new Customer(res.getString(2), res.getString(3), res.getString(6), res.getString(4), res.getString(5), res.getString(1), res.getInt(7)==1,res.getString(8)));
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		
		return arr;
	}
}
